package com.qiyi.player.core.ad.render
{
   import flash.events.EventDispatcher;
   import com.qiyi.player.core.IDestroy;
   import flash.display.Sprite;
   import com.qiyi.player.core.video.decoder.AdDecoder;
   import flash.media.Video;
   import flash.geom.Rectangle;
   
   public class AdRender extends EventDispatcher implements IDestroy
   {
      
      public function AdRender(param1:Sprite) {
         super();
         this._adArea = new Rectangle();
         this._parent = param1;
         this._video = new Video();
         this._video.smoothing = true;
      }
      
      protected var _parent:Sprite;
      
      protected var _decoder:AdDecoder;
      
      protected var _video:Video;
      
      protected var _adArea:Rectangle;
      
      public function show(param1:Boolean) : void {
         if(param1)
         {
            this._parent.addChild(this._video);
         }
         else if(this._video.parent)
         {
            this._parent.removeChild(this._video);
         }
         
      }
      
      public function bind(param1:AdDecoder) : void {
         this._decoder = param1;
         if(this._decoder)
         {
            this._video.attachNetStream(this._decoder.netstream);
         }
         else
         {
            this._video.attachNetStream(null);
         }
      }
      
      public function setADRect(param1:int, param2:int, param3:int, param4:int) : void {
         if(!(this._adArea.x == param1) || !(this._adArea.y == param2) || !(this._adArea.width == param3) || !(this._adArea.height == param4))
         {
            this._adArea.x = param1;
            this._adArea.y = param2;
            this._adArea.width = param3;
            this._adArea.height = param4;
            this._video.x = param1;
            this._video.y = param2;
            this._video.width = param3;
            this._video.height = param4;
         }
      }
      
      public function clear() : void {
         this._video.clear();
      }
      
      public function getADArea() : Rectangle {
         return this._adArea;
      }
      
      public function destroy() : void {
         if(this._video)
         {
            if(this._video.parent)
            {
               this._parent.removeChild(this._video);
               this._parent = null;
            }
            this._video.attachNetStream(null);
         }
         this._decoder = null;
         this._parent = null;
      }
   }
}
